package cc.comac.mom.service.impl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cc.comac.mom.api.QualityPclrTestInvoiceService;
import cc.comac.mom.bean.QualityPclrTestInvoice;
import cc.comac.mom.bean.QualityReject;
import cc.comac.mom.bean.base.LimitPageBean;
import cc.comac.mom.datahandlers.entity.QualityPclrTestInvoiceDataHandler;
import cc.comac.mom.entity.PclrTestInvoicePrint;
import cc.comac.mom.entity.QualityPclrTestInvoiceEntity;
import cc.comac.mom.model.table.jflow.UsersDO;
import cc.comac.mom.util.ResultBean;
import cc.comac.mom.util.user.UserUtil;

@Service
@RestController
public class QualityPclrTestInvoiceServiceImpl implements QualityPclrTestInvoiceService {

	@Autowired
	private UserUtil userUtil;
	@Autowired
	private QualityPclrTestInvoiceDataHandler qualityPclrTestInvoiceDataHandler;

	// 修改实验分类
	@Override
	public ResultBean updateTestClassify(@RequestBody QualityPclrTestInvoice obj) {
		// TODO Auto-generated method stub
		return qualityPclrTestInvoiceDataHandler.updateTestClassify(obj);
	}

	@Override
	public ResultBean selectByCondition(@RequestBody QualityPclrTestInvoice obj) {
		ResultBean resultBean = new ResultBean(true);
		LimitPageBean<QualityPclrTestInvoiceEntity> limitPageBean = qualityPclrTestInvoiceDataHandler
				.selectByCondition(obj);
		resultBean.setObject(limitPageBean);
		return resultBean;
	}

	@Override
	public ResultBean receiveCompletedByTestNo(@RequestBody QualityPclrTestInvoice obj) {
		// TODO Auto-generated method stub
		return qualityPclrTestInvoiceDataHandler.receiveCompletedByTestNo(obj);
	}

	@Override
	public ResultBean beginTestByTestNo(@RequestParam String testNo) {
		// TODO Auto-generated method stub
		return qualityPclrTestInvoiceDataHandler.beginTestByTestNo(testNo);
	}

	@Override
	public ResultBean submitReject(@RequestBody QualityReject QualityReject) {
		UsersDO usersDO=userUtil.getUserInfoByEcode(QualityReject.getInnerData().getRejectUserJobNumber());
		QualityReject.getInnerData().setRejectUser(usersDO.getTruename());
		ResultBean submitReject = qualityPclrTestInvoiceDataHandler.submitReject(QualityReject);
		return submitReject;
	}


	@Override
	public ResultBean submitAuditByTestNo(@RequestParam String testNo) {
		// TODO Auto-generated method stub
		return qualityPclrTestInvoiceDataHandler.submitAuditByTestNo(testNo);
	}

	@Override
	public ResultBean auditCompletedByTestNo(@RequestParam String testNo) {
		// TODO Auto-generated method stub
		return qualityPclrTestInvoiceDataHandler.auditCompletedByTestNo(testNo);
	}

	@Override
	public ResultBean getByTestNo(@RequestParam String testNo) {
		// TODO Auto-generated method stub
		return qualityPclrTestInvoiceDataHandler.getByTestNo(testNo);
	}

	@Override
	public String exportData(HttpServletRequest request, HttpServletResponse response, @RequestBody QualityPclrTestInvoice obj) {
		String exportData = qualityPclrTestInvoiceDataHandler.exportData(request, response, obj);
		return exportData;
	}

	@Override
	public PclrTestInvoicePrint printPclrTestInvoice(@RequestParam String testNo) throws Exception {
		PclrTestInvoicePrint printPclrTestInvoice = qualityPclrTestInvoiceDataHandler.printPclrTestInvoice(testNo);
		return printPclrTestInvoice;
	}

	@Override
	public PclrTestInvoicePrint printNdtTestInvoice(@RequestParam String testNo) throws Exception {
		PclrTestInvoicePrint printNdtTestInvoice = qualityPclrTestInvoiceDataHandler.printNdtTestInvoice(testNo);
		return printNdtTestInvoice;
	}

}
